import { genusAll, getGenusByIdOrByGenusName } from "@/api/genus";

const getDefaultState = () => {
  return {};
};

const state = getDefaultState();

const mutations = {};

const actions = {
  //查看所有科
  async genusAll({ state }, id) {
    return new Promise((resolve, reject) => {
      genusAll(id).then(response => {
        if (response.success) {
          resolve(response.data);
        } else {
          reject(response);
        }
      });
    });
  },
  //根据名称获取属
  async getGenusByIdOrByGenusName({ state }, name) {
    return new Promise((resolve, reject) => {
      getGenusByIdOrByGenusName(name).then(response => {
        if (response.success) {
          resolve(response.data);
        } else {
          reject(response);
        }
      });
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
